<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>人事信息管理系统</title>
   <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
   <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
   <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="resources/layer/layer.js"></script>
</head>
<body>
	<div class="jumbotron text-center" style="margin-bottom:0">
		<h3>人才信息录入</h3>
		<form method="post" action="addData">
			<table class="table table-bordered">
	        <caption>•人才信息管理——人才信息录入（以下带<span style="color: red">*</span>为必填项）</caption>
		        <tr>
		            <td>编　号：<input type="text" name="id" size="45" /><span style="color: red">*</span></td>
		        </tr>
		         <tr>
		            <td>姓　名：<input type="text" name="name" size="45" /><span style="color: red">*</span></td>
		        </tr>
		         <tr>
		            <td>性　别：<label><input checked type="radio" name="sex" value="1">男</label>
						     <label><input type="radio" name="sex" value="0">女</label>
							 <span style="color: red">*</span>
							 <span style="margin:0 155px"></span>
					</td>
		        </tr>
		         <tr>
		            <td>身 份 证：<input type="text" name="idcard" size="45" /><span style="color: red">*</span></td>
		        </tr>
		         <tr>
		            <td>出生日期：<input type="text" name="birth" size="45" placeholder="日期格式例子：2020-09-26" /><span style="color: red">*</span></td>
		        </tr>
		         <tr>
		            <td>联系电话：<input type="text" name="phone" size="45" /></td>
		        </tr>
		     </table>
			<button type="button" class="btn btn-success text-center" onclick="submitAdd();">确定</button>
​		</form>
	</div>
</body>
</html>
<script type="text/javascript">
function submitAdd(){
	// 非空判断
	if($('[name="id"]').val() == ''){ layer.alert("编号必须填写")}
	else if($('[name="name"]').val() == ''){ layer.alert("姓名必须填写")}
	else if($('[name="idcard"]').val() == ''){ layer.alert("身份证必须填写")}
	else if($('[name="birth"]').val() == ''){ layer.alert("出生日期必须填写")}
	else {
		// 设置定时器
		let time = setTimeout(()=>{layer.msg("很遗憾，添加人才信息出错",{icon:0})}, 2000);
		// 表单提交地址
        let url = $("form").attr('action');
        // 表单序列化
        let data = $("form").serialize();
        // jquery post提交
        $.post(url,data).then((ret)=>{
        	// 清除定时器
        	clearTimeout(time);
            if(ret == "success"){
                layer.msg("恭喜，添加人才信息成功！",{icon:1,time:1500},()=>{
                    location.href = "list"
                })
            }else{
                layer.msg("很遗憾，添加人才信息失败",{icon:2,time:1500});
            }
        });
     }
}
</script>